package com.dailyblue.java.cloud.consumer.basic.service.impl;

import com.dailyblue.java.cloud.consumer.basic.service.ConsumerService;
import com.dailyblue.java.commons.util.JsonResult;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@Service
public class Consumer02ServiceImpl implements ConsumerService {
    @Resource
    private RestTemplate restTemplate;

    @Override
    public JsonResult a() {
        // 这里是有服务器来决定获取那个实例，默认是轮询方式
        // http://localhost:8011/provider/a
        // http://localhost:8012/provider/a
        // http://localhost:8013/provider/a
        // 提供服务名获取到集群中的某个实例
        return restTemplate.getForObject("http://provider/provider/a", JsonResult.class);
    }

    @Override
    public JsonResult b(int a) {
        return restTemplate.getForObject("http://provider/provider/b/" + a, JsonResult.class);
    }

    @Override
    public JsonResult c(int a, String b) {
        return restTemplate.getForObject("http://provider/provider/c/" + a + "/" + b, JsonResult.class);
    }
}
